#!/bin/bash

WARN_VALUE=90

diskstr=`df -h | awk {'print $5'} | sed 's/%//g'`
disks=(${diskstr// / })

warnOpt()
{
# send warning mail
echo "!!!Disk warning!!!" > /home/system-monitor/disk_warning.txt
date "+%Y-%m-%d %H:%M:%S" >> /home/system-monitor/disk_warning.txt
echo "*******************" >> /home/system-monitor/disk_warning.txt
echo "hostname : " `hostname` >> /home/system-monitor/disk_warning.txt
echo "*******************" >> /home/system-monitor/disk_warning.txt
echo "server ip info:" >> /home/system-monitor/disk_warning.txt
/sbin/ifconfig | grep 'inet addr' | awk '{print $2}' >> /home/system-monitor/disk_warning.txt
echo "*******************" >> /home/system-monitor/disk_warning.txt
echo "disk usage:" >> /home/system-monitor/disk_warning.txt
df -h >> /home/system-monitor/disk_warning.txt
cat /home/system-monitor/disk_warning.txt | mail -s 'Disk warning' appdev@qiujieda.com hxiufeng@qiujieda.com zgc@qiujieda.com
}

for ((i=1;i<${#disks[*]};i++))
    do
        if [ ${disks[i]} -gt $WARN_VALUE ];then
            warnOpt
            break
        fi
    done
